<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:replace="common/head::head('','/css/signin/signin.css','/js/jquery-validate/jquery.validate.min.js')">
</head>
<script th:inline="javascript">
    /*<![CDATA[*/

    var basePath = /*[[${#httpServletRequest.getScheme() + "://" + #httpServletRequest.getServerName() + ":" + #httpServletRequest.getServerPort() + #httpServletRequest.getContextPath()}]]*/ 'basepath';

    function updPassword(){
        var userId = $("input[name='userId']:eq(0)").val();
        var username = $("input[name='username']:eq(0)").val();
        var password1 = $("input[name='password1']:eq(0)").val();
        var password2 = $("input[name='password2']:eq(0)").val();
        if(password1 == "" || password2 == ""){
            $("#loginMessage").html("密码不能为空");
            $("#loginMessageDiv").fadeIn();
            return false;
        }
        var url = basePath+"/lims/user/updPassword"
        $.post({
            url:url,
            data:{'userId':userId,"username":username,"password":password1},
            dataType:'json',
            success:function(data){
                if(data){
                    alert("修改成功");
                    parent.location.href="/logout";
                }
            }
        });
    }
    $(function(){
        $('#upPassForm').validate({
            rules:{
                password1:{
                    required:true,
                    minlength:6
                },
                password2:{
                    required:true,
                    minlength:6,
                    equalTo:'#password1'
                }

            },
            messages:{
                password1:{
                    required:'请输入密码',
                    minlength:'至少为6位长度的密码'
                },
                password2:{
                    required:'请输入密码',
                    minlength:'至少为6位长度的密码',
                    equalTo:'两次密码必须一致'
                }
            }
        });

    });
    /*]]>*/
</script>


<body>
<div class="container">
    <form class="form-signin" th:id="upPassForm">
        <div th:id="loginMessageDiv" class="alert alert-danger alert-dismissable" style="width: 370px;
            margin-bottom: 15px;display: none">
            <button type="button" class="close" data-dismiss="alert"></button>
            <strong th:id="loginMessage"></strong>
        </div>
        <div class="form-group">
            <input type="hidden" th:name="userId" th:value="${user.userId}" class="form-control form-signin">
        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" style="height: 50px;margin-top: 10px;">用户名</span>
            </div>
            <input type="text" th:name="username" th:value="${user.username}" th:readonly="readonly" class="form-control form-signin">
        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" style="height: 50px;margin-top: 10px;">新密码</span>
            </div>
            <input type="password" th:name="password1" th:id="password1" class="form-control form-signin" autofocus="autofocus"   placeholder="请输入新密码">

        </div>
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" style="height: 50px;margin-top: 10px;">新密码</span>
            </div>
            <input type="password" th:name="password2" th:id="password2" class="form-control form-signin"  placeholder="请再次输入新密码">
        </div>

        <button class="btn btn-lg btn-primary btn-block" th:type="button" th:onclick="'javascript:updPassword()'">确认修改</button>
    </form>
</div>


</body>
</html>